{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "1\n",
      "6\n",
      "6\n",
      "2\n",
      "4\n",
      "6\n",
      "6\n",
      "7\n",
      "7\n",
      "[1, 2, 3, 4, 5, 6, 7]\n"
     ]
    }
   ],
   "source": [
    "from random import choice\n",
    "short_list=[1,2,3,4,5,6,7]\n",
    "for i in range(10):\n",
    "    print(choice(short_list))\n",
    "print(short_list)\n",
    "try:\n",
    "    short_list[5]\n",
    "except Exception as other:\n",
    "    print(other)\n",
    "except :\n",
    "    print('下标越界')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "抛出异常\n"
     ]
    },
    {
     "ename": "UppercaseException",
     "evalue": "WORLD",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mUppercaseException\u001b[0m                        Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-9-fd0929b9fba3>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[1;32mif\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'抛出异常'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m     \u001b[1;32mraise\u001b[0m \u001b[0mUppercaseException\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'WORLD'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mUppercaseException\u001b[0m: WORLD"
     ]
    }
   ],
   "source": [
    "class UppercaseException(Exception):\n",
    "    pass\n",
    "if(True):\n",
    "    print('抛出异常')\n",
    "    raise UppercaseException('WORLD')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
